﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Xml.Linq;

namespace OurMemory
{    
    public partial class FormEditOF : Form
    {
        private readonly OurFavorServices services = new OurFavorServices();

        private Guid id;
        public FormEditOF()
        {
            InitializeComponent();
        }
        /// <summary>
        /// 从上级窗体导入id
        /// </summary>
        /// <param name="id"></param>
        public FormEditOF(Guid id)
        {
            InitializeComponent();
            var item = services.GetById(id);
            if (item != null)
            {
                textWho.Text = item.Who;
                textWishes.Text = item.Wishes;
                textFavor.Text = item.Favor;
                textPhoto.Text = item.Photo;
                this.id = id;
            }
        }

        private void btnOk_Click(object sender, EventArgs e)
        {
            OurFavorEditModel model = new OurFavorEditModel()
            {
                Id = this.id,
                Who = textWho.Text,
                Wishes = textWishes.Text,
                Favor = textFavor.Text,
                Photo= textPhoto.Text,
            };
            services.Edit(model);
            this.DialogResult = DialogResult.OK;
            this.Close();
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.DialogResult = DialogResult.Cancel;
            this.Close();
        }
    }
}
